#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0xD784;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FFD0EC34_my(){ 
 asm volatile(
                "STMFD   SP!, {R0-R10,LR}\n"
                "MOV     R6, #0\n"
                "MOV     R4, R0\n"
                "BL      sub_FFD0F760\n"
                "MVN     R1, #0\n"
                "BL      sub_FFC18FE0\n"
                "MOV     R2, #4\n"
                "ADD     R1, SP, #8\n"
                "MOV     R0, #0x8A\n"
                "BL      sub_FFC5AECC\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x20A\n"
                "LDRNE   R0, =0xFFD0EE08\n"
                "BLNE    sub_FFC0BFC8\n"
                "LDR     R8, =0x1CE6C\n"
                "LDR     R5, =0x1CDB8\n"
                "LDRSH   R1, [R8,#0xE]\n"
                "LDR     R0, [R5,#0x7C]\n"
            //  "BL      nullsub_22\n"
                "BL      sub_FFC39CC4\n"
                "LDR     R2, =0xD788\n"
                "ADD     R3, R4, #0x8C\n"
                "STRH    R0, [R4,#0x88]\n"
          //    "STRD    R2, [SP]\n"       // replaced by 2 STR's
                "STR     R2, [SP]\n"
                "STR     R3, [SP,#4]\n"
                "MOV     R1, R0\n"
                "LDRH    R0, [R5,#0x54]\n"
                "LDRSH   R2, [R8,#0xC]\n"
                "LDR     R3, =0xD784\n"
                "BL      sub_FFD0FC54\n"
                "BL      wait_until_remote_button_is_released\n"
                "BL      capt_seq_hook_set_nr\n"  //+
                "B       sub_FFD0ECA8\n"
 );
}

void __attribute__((naked,noinline)) sub_FFC4DED8_my(){ 
 asm volatile(
                "STMFD   SP!, {R4-R6,LR}\n"
                "LDR     R4, [R0,#0xC]\n"
                "LDR     R6, =0x1CDB8\n"
                "LDR     R0, [R4,#8]\n"
                "MOV     R5, #0\n"
                "ORR     R0, R0, #1\n"
                "STR     R0, [R4,#8]\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "MOVEQ   R0, #2\n"
                "BLEQ    sub_FFC48FB4\n"
                "BL      sub_FFD0D5B8\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FFC4DF58\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0DA4C\n"
                "TST     R0, #1\n"
                "MOVNE   R2, R4\n"
                "LDMNEFD SP!, {R4-R6,LR}\n"
                "MOVNE   R1, #1\n"
                "BNE     sub_FFC4C398\n"
                "BL      sub_FFD22B90\n"
                "BL      sub_FFC5B05C\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0EB4C\n"
                "BL      sub_FFD0F5F4\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0EC34_my\n" //--------------->
                "BL      capt_seq_hook_raw_here\n"  //+
                "MOV     R5, R0\n"
                "B       loc_FFC4DF68\n"
"loc_FFC4DF58:\n"
                "LDR     R0, =0x565C\n"
                "LDR     R0, [R0,#4]\n"
                "CMP     R0, #0\n"
                "MOVNE   R5, #0x1D\n"
"loc_FFC4DF68:\n"
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "MOV     R0, R5\n"
                "BL      sub_FFC4C398\n"
                "BL      sub_FFD0F03C\n"
                "CMP     R0, #0\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x2000\n"
                "STRNE   R0, [R4,#8]\n"
                "LDMFD   SP!, {R4-R6,PC}\n"
 );
}


void __attribute__((naked,noinline)) task_CaptSeqTask_my() 
{
	asm volatile (
                "STMFD   SP!, {R3-R9,LR}\n"
                "LDR     R6, =0x1CDB8\n"
                "LDR     R5, =0x565C\n"
                "MOV     R9, #1\n"
                "MOV     R7, #0\n"
"loc_FFC4DB9C:\n"
                "LDR     R0, [R5,#0xC]\n"
                "MOV     R2, #0\n"
                "MOV     R1, SP\n"
                "BL      sub_FFC19230\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFC4DBC8\n"
                "LDR     R1, =0x43F\n"
                "LDR     R0, =0xFFC4D8F8\n"
                "BL      sub_FFC0BFC8\n"
                "BL      sub_FFC0BD80\n"
                "LDMFD   SP!, {R3-R9,PC}\n"
"loc_FFC4DBC8:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0]\n"
                "CMP     R1, #0x18\n"
                "ADDLS   PC, PC, R1,LSL#2\n"
                "B       loc_FFC4DDC4\n"
"loc_FFC4DBDC:\n"
                "B       loc_FFC4DC40\n"
"loc_FFC4DBE0:\n"
                "B       loc_FFC4DCA8\n"
"loc_FFC4DBE4:\n"
                "B       loc_FFC4DCB0\n"
"loc_FFC4DBE8:\n"
                "B       loc_FFC4DCC8\n"
"loc_FFC4DBEC:\n"
                "B       loc_FFC4DCBC\n"
"loc_FFC4DBF0:\n"
                "B       loc_FFC4DCD0\n"
"loc_FFC4DBF4:\n"
                "B       loc_FFC4DCD8\n"
"loc_FFC4DBF8:\n"
                "B       loc_FFC4DCE0\n"
"loc_FFC4DBFC:\n"
                "B       loc_FFC4DD38\n"
"loc_FFC4DC00:\n"
                "B       loc_FFC4DD44\n"
"loc_FFC4DC04:\n"
                "B       loc_FFC4DD4C\n"
"loc_FFC4DC08:\n"
                "B       loc_FFC4DD54\n"
"loc_FFC4DC0C:\n"
                "B       loc_FFC4DD5C\n"
"loc_FFC4DC10:\n"
                "B       loc_FFC4DD64\n"
"loc_FFC4DC14:\n"
                "B       loc_FFC4DD6C\n"
"loc_FFC4DC18:\n"
                "B       loc_FFC4DD74\n"
"loc_FFC4DC1C:\n"
                "B       loc_FFC4DD7C\n"
"loc_FFC4DC20:\n"
                "B       loc_FFC4DD84\n"
"loc_FFC4DC24:\n"
                "B       loc_FFC4DD8C\n"
"loc_FFC4DC28:\n"
                "B       loc_FFC4DD94\n"
"loc_FFC4DC2C:\n"
                "B       loc_FFC4DD9C\n"
"loc_FFC4DC30:\n"
                "B       loc_FFC4DDA8\n"
"loc_FFC4DC34:\n"
                "B       loc_FFC4DDB4\n"
"loc_FFC4DC38:\n"
                "B       loc_FFC4DDBC\n"
"loc_FFC4DC3C:\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DC40:\n"
                "BL      sub_FFD0D5DC\n"

                "BL      shooting_expo_param_override\n"  // +

                "BL      sub_FFC4BF50\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FFC4DDD0\n"
                "BL      sub_FFC4D5C4\n"
                "MOV     R4, R0\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FFC4DC88\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FFC50E70\n"
                "TST     R0, #1\n"
                "STRNE   R9, [R5,#4]\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x40000000\n"
                "STRNE   R0, [R4,#8]\n"
                "BNE     loc_FFC4DDD0\n"
"loc_FFC4DC88:\n"
                "BL      sub_FFD22B90\n"
                "BL      sub_FFC5B05C\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0EC34_my\n"         //------------>
                "BL      capt_seq_hook_raw_here\n"  //+
                "TST     R0, #1\n"
                "STRNE   R9, [R5,#4]\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DCA8:\n"
                "BL      sub_FFC4DED8_my\n"    //----------------->
                "B       loc_FFC4DCC0\n"
"loc_FFC4DCB0:\n"
                "MOV     R0, #1\n"
                "BL      sub_FFD0D780\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DCBC:\n"
                "BL      sub_FFD0D278\n"
"loc_FFC4DCC0:\n"
                "STR     R7, [R6,#0x24]\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DCC8:\n"
                "BL      sub_FFD0D5A8\n"
                "B       loc_FFC4DCC0\n"
"loc_FFC4DCD0:\n"
                "BL      sub_FFD0D5B0\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DCD8:\n"
                "BL      sub_FFD0D6A0\n"
                "B       loc_FFC4DD3C\n"
"loc_FFC4DCE0:\n"
                "LDR     R4, [R0,#0xC]\n"
                "BL      sub_FFD0D5B8\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0DDCC\n"
                "TST     R0, #1\n"
                "MOV     R8, R0\n"
                "BNE     loc_FFC4DD20\n"
                "BL      sub_FFC5B05C\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0EB4C\n"
                "MOV     R0, R4\n"
                "BL      sub_FFD0F09C\n"
                "MOV     R8, R0\n"
                "LDR     R0, [R4,#0x14]\n"
                "BL      sub_FFC5B270\n"
"loc_FFC4DD20:\n"
                "BL      sub_FFD0D5A8\n"
                "MOV     R2, R4\n"
                "MOV     R1, #8\n"
                "MOV     R0, R8\n"
                "BL      sub_FFC4C398\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD38:\n"
                "BL      sub_FFD0D6FC\n"
"loc_FFC4DD3C:\n"
                "BL      sub_FFC4BF50\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD44:\n"
                "BL      sub_FFD0D5A8\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD4C:\n"
                "BL      sub_FFD0E038\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD54:\n"
                "BL      sub_FFD0E1F0\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD5C:\n"
                "BL      sub_FFD0E280\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD64:\n"
                "BL      sub_FFD0E334\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD6C:\n"
                "BL      sub_FFD0E51C\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD74:\n"
                "BL      sub_FFD0E56C\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD7C:\n"
                "MOV     R0, #0\n"
                "B       loc_FFC4DDA0\n"
"loc_FFC4DD84:\n"
                "BL      sub_FFD0E730\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD8C:\n"
                "BL      sub_FFD0E7C4\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD94:\n"
                "BL      sub_FFD0E884\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DD9C:\n"
                "MOV     R0, #1\n"
"loc_FFC4DDA0:\n"
                "BL      sub_FFD0E5F0\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DDA8:\n"
                "BL      sub_FFD0D8A4\n"
                "BL      sub_FFC15B18\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DDB4:\n"
                "BL      sub_FFD0E3F0\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DDBC:\n"
                "BL      sub_FFD0E45C\n"
                "B       loc_FFC4DDD0\n"
"loc_FFC4DDC4:\n"
                "LDR     R1, =0x523\n"
                "LDR     R0, =0xFFC4D8F8\n"
                "BL      sub_FFC0BFC8\n"
"loc_FFC4DDD0:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0,#4]\n"
                "LDR     R0, [R5,#8]\n"
                "BL      sub_FFC18FAC\n"
                "LDR     R4, [SP]\n"
                "LDR     R0, [R4,#8]\n"
                "CMP     R0, #0\n"
                "MOVEQ   R1, #0xFC\n"
                "LDREQ   R0, =0xFFC4D8F8\n"
                "BLEQ    sub_FFC0BFC8\n"
                "STR     R7, [R4,#8]\n"
                "B       loc_FFC4DB9C\n"
    );
} 
